<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/comment' }">评论管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-tabs>
      <el-tab-pane label="审核">
        <el-table :data="tableData" height="500" size="medium" border stripe style="width: 100%">
          <el-table-column fixed prop="cid" label="评价编号" width="100"></el-table-column>
          <el-table-column prop="rid" label="房间编号" width="80"></el-table-column>
          <el-table-column prop="uid" label="用户编号" width="120"></el-table-column>
          <el-table-column prop="cdate" label="评论时间" width="170"></el-table-column>
          <el-table-column prop="oid" label="订单编号" width="150"></el-table-column>
          <el-table-column prop="content" label="评价内容" width="300"></el-table-column>
          <el-table-column prop="score" label="评分（1-5）" width="100"></el-table-column>
          <!-- 审核状态 -->
          <el-table-column prop="state" label="状态" width="100">
            <template slot-scope="scope">
            <el-tag  type="info" @click="changeState(scope.row)" v-show="status == 1" >未审核</el-tag>
            <el-tag  type="success" @click="changeState(scope.row)" v-show="status == 0">已审核</el-tag>
             </template>
          </el-table-column>
          <!-- 删除按钮 -->
          <el-table-column label="操作" width="180">
            <template slot-scope="scope">
              <el-button type="danger" size="small" @click="del(id,scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="page"
      :total="total"
      :page-size="limit"
      @current-change="goPage"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      limit: 5,
      id:0,
      total:100,
      page:1,
      status:1,
      tableData: [],
    };
  },
  created() {
     this.getData()
  },
  methods:{
    changeState(row){
      console.log(row.status)
    },
  
    goPage(page) {
      this.page = page;
      this.getData()
    },
     getData(){
     this.$http({
     url:'/comment/getAll',
     method:'get',
     params:{
       page:this.page,
       limit:this.limit
     }
     }).then(res=>{
        this.tableData= res.data
        this.total = res.count
      })
     },
      del(id,row){
      this.$confirm(`确定要删除编号为【${row.cid}】的信息吗？`, '提示', {
          confirmButtonText: '删除',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: '/comment/delete',
            params: {
            id:row.cid
            } 
          }).then(res=>{
            console.log(res)
            this.$message({
              type: res.code == 0 ? 'success' : 'error',
              message: res.msg
            });
            if(res.code == 0){
              this.getData()
            }
          })
        }).catch(() => {});
    },
  }
}

</script>

<style scoped>
.el-breadcrumb {
  height: 40px;
  width: 100%;
  font-size: 12px;
  line-height: 40px;
  padding-left: 15px;
  border-bottom: 1px solid #e5e5e5;
}
.el-tabs {
  padding-left: 10px;
  font-size: 12px;
}
.el-tab-pane {
  padding: 10px;
}
.el-table {
  text-align: center;
}
.el-table thead {
  color: #000;
}
.el-tag {
  cursor: pointer;
}
</style>